package Core 
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	
	/**
	 * ...
	 * @author Serg de Adelantado
	 */
	public class ImageDeleter extends Sprite 
	{
		private var FIconRed:Bitmap;
		private var FIconGray:Bitmap;
		private var FImage:ImageContainer;
		
		public function ImageDeleter(AImage:ImageContainer) 
		{
			FImage = AImage;
			FImage.addChild(this);			
			FIconRed = new Bitmap(new DeleteRed());
			FIconGray = new Bitmap(new DeleteGray());
			addChild(FIconRed);
			addChild(FIconGray);
			FIconRed.visible = false;
			x = FImage.width - width - 3;
			y = 3;
			focusRect = false;
			addEventListener(MouseEvent.MOUSE_DOWN, OnMouseDown);
			filters = [new GlowFilter(0xFFFFFF, 1, 4, 4, 1, 3)];
		}		
			
		private function OnMouseDown(e:MouseEvent):void 
		{
			FImage.MarkedForDelete = !FImage.MarkedForDelete;
			Delete = FImage.MarkedForDelete;
		}
		
		public function set Delete(ADelete:Boolean):void
		{
			FIconRed.visible = ADelete;
			FIconGray.visible = !ADelete;
		}	
		
		public function Destroy():void 
		{
			FIconRed.bitmapData.dispose();
			FIconGray.bitmapData.dispose();
			removeChild(FIconRed);
			removeChild(FIconGray);
			if (parent)
				parent.removeChild(this);
		}
	}
}